﻿using System;
using System.IO;
using System.Collections.Generic;


namespace Voize
{
    internal class CConfig
    {


        internal CConfig()
        {
            m_FullConfigPath = Environment.GetEnvironmentVariable("APPDATA");
            m_FullConfigPath += @"\Voize\";

            if (!Directory.Exists(m_FullConfigPath))
                Directory.CreateDirectory(m_FullConfigPath);

            m_FullConfigPath += m_ConfigFile;

            if (!File.Exists(m_FullConfigPath))
                File.Create(m_FullConfigPath);
        }

        private const string m_ConfigFile = "config";
        private string m_FullConfigPath;


        internal void SaveFileAssociation(List<string> extensions)
        {
            StreamWriter writer = new StreamWriter(m_FullConfigPath);

            foreach(string ext in extensions)
                writer.WriteLine(ext);
            writer.Close();
        }

        internal bool GetFileAssociationStatus(string extension)
        {
            bool retval = false;
            string line;

            StreamReader reader = new StreamReader(m_FullConfigPath);
            
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Equals(extension))
                {
                    retval = true;
                    break;
                }
                else
                    retval = false;
            }

            reader.Close();

            return retval;
        }
    }
}
